#import "MyClassViewController.h"
#import "SMViewController.h"

@interface MyClassViewController ()

@end

@implementation MyClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.itemTableView.delegate = self;
    self.itemTableView.dataSource = self;
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)itemCallback:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    static NSString *CellIdentifier = @"CellStyleMyClass";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellStyleMyClass"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        switch (section) {
            case 0:
                if (row == 0) {
                    cell.textLabel.text = @"豆豆班";

                }else if (row == 1){
                    cell.textLabel.text = @"果果班";
                }
                break;
            case 1:
                if (row == 0) {
                    cell.textLabel.text = @"加入班级";
                    cell.textLabel.textColor = [UIColor redColor];
                }
                break;
            default:
                break;
        }
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%@",indexPath);
    //该方法响应列表中行的点击事件
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    NSString *str = [NSString stringWithFormat:@"事件id： section:%ld,row:%ld",(long)section,(long)row];
    //indexPath.row得到选中的行号，提取出在数组中的内容。
    UIAlertView *myAlertView;
    myAlertView = [[UIAlertView alloc]initWithTitle:@"检测到点击事件" message:str delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [myAlertView show];
    //点击后弹出该对话框。
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    //更新当前点击的行的信息
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }
    else{
        return 1;
    }
}

//设置Cell行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

//设置头高
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 2;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
